var navdata = require("../../database/data.js")
var app = getApp()
//获取应用实例
Page({
  data: {
    hiddenNames: true,
    showCenterDialog: true,
    defName: false,
    more: true,
    isShow: '',
    navImg: {},
    nav: {},
    contents: {}
  },
  onShareAppMessage: function () {
    return {
      title: '短信群发库 - 奇思妙想的短信内容，创意十足的短信模板',
      path: '/page/index',
      success: function (res) {
        var shareTickets = res.shareTickets;
        if (shareTickets.length == 0) {
          return false;
        }
        wx.getShareInfo({
          shareTicket: shareTickets[0],
          success: function (res) {
            var encryptedData = res.encryptedData;
            var iv = res.iv;
          }
        })
        
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  /**
 * 生命周期函数--监听页面加载
 */
  //数据加载
  onLoad: function (event) {
    wx.showShareMenu({
      withShareTicket: true
    });
    //获取数据
    wx.showLoading({
      title:"加载中",
      mask:true
    });
    var parameter = {
      cid: "1,2,3,4,5,6,7,8,10",
      num: "1",
      page: "2",
      isChoice: 1
    };
    var getApinavUrl = app.globalData.smsbaoApi + "/batch/sapi/get_sms_cate";
    var getApiContUrl = app.globalData.smsbaoApi + "/batch/sapi/get_sms_content";
    this.getApiData(getApiContUrl, parameter, "contents");
    this.getApiData(getApinavUrl, '', "nav");
    this.setData({
      navImg: navdata.nav,
    })
  },
  //封装请求地址函数
  getApiData: function (url, parameter, settedKey) {
    let that = this
    wx.request({
      url: url,
      data: parameter,
      method: "post",
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.data.code == '200') {
        var arrData = {};
        arrData[settedKey] = res.data.data;
        that.setData(arrData);
        }
        setTimeout(function () {
          wx.hideLoading()
        }, 1000)
      },
      fail: function (error) {
        console.log(error)
      }
    })
  },

  //跳转短信发送页面
  onBatchTo: function (event) {
    var data = event.currentTarget.dataset;
    wx.navigateTo({
      url: '/pages/batch/batch?data=' + JSON.stringify(data) + "&class=" + 0,
    })
  },
  //跳转详情
  onNavTo: function (event) {
    var nav = event.currentTarget.dataset;

    wx.navigateTo({
      url: "/pages/list/list?nav=" + JSON.stringify(nav),
    })
  },
  onMore: function (event) {
    wx.navigateTo({
      url: "/pages/list/more-selected/more-selected",
    })
  },

  //更多
  onNavMore: function (event) {
    this.setData({
      hiddenNames: !this.data.hiddenNames,
      defName: !this.data.defName,
      more: !this.data.more
    })
  }
})
